package com.connector.base.handler;

import com.connector.base.connection.Connection;
import com.connector.base.message.MessageHandler;
import com.connector.base.message.model.BaseMessage;
import com.connector.base.protocol.Packet;

public abstract class BaseMessageHandler<T extends BaseMessage> implements MessageHandler
{
    public abstract T decode(final Packet packet, final Connection connection);

    public abstract void handle(final T message);

    @Override
    public void handle(final Packet packet, final Connection connection) {
        final T t = this.decode(packet, connection);
        if (t != null) {
            t.decodeBody();
            this.handle(t);
        }
    }
}
